<?php
namespace app\crm\controller;
use think\Loader;

class Goodsattribute extends CrmController
{
    /**
     * 商品属性列表界面
     * @return [type] [description]
     */
    public function goodsAttributeList()
    {
		//分配增删改的权限
		$menuname = "Goods Attribute";
		$p_menuname = $_SESSION['menu'][$menuname]; //父菜单
		$priv = $_SESSION["user_priv"][$p_menuname][$menuname];	
		$this->assign("username",$_SESSION['user_info']['username']);
        $this->assign("priv",$priv);
        // 模板输出
        return $this->fetch('goodsAttributeList');
    }

	/**
     * tianjia商品属性列表界面
     * @return [type] [description]
     */
    public function addAttribute()
    {
        $typeData = Loader::model('Goodsattribute')->getShopType();
        $this->assign("typeData",$typeData);
		// 模板输出
        return $this->fetch('addAttribute');
    }
	
	/**
     * 调用model的属性添加方法
     */
    public function insertAttribute()
    {
        //print_r($_REQUEST);die;
        Loader::model('Goodsattribute')->insertAttribute($_REQUEST);
    }
	
	/**
     * 修改商品属性列表界面
     */
    public function editAttribute()
    {
        $id = $_GET["id"];
		$typeData = Loader::model('Goodsattribute')->getShopType();
        $this->assign("typeData",$typeData);
        $arrData = Loader::model('Goodsattribute')->getAttributeArr($id);
        $this->assign("arrData",$arrData);
        // 模板输出
        return $this->fetch('editAttribute');
    }
	
	/**
     * 调用model的属性更新方法
     */
    public function updateAttribute()
    {
        $id = $_GET["id"];
        $data = array(
            'type_id' => $_REQUEST['type_id'],
            'attr_name' => $_REQUEST['attr_name'],
            'attr_en_name' => $_REQUEST['attr_en_name'],
			'attr_values' => $_REQUEST['attr_values'],
			'text_type' => $_REQUEST['text_type']
        );
        Loader::model('Goodsattribute')->updateAttribute($id,$data);
    }


    /**
     * 删除商品属性
     * @return [type] [description]
     */
    public function delAttribute()
    {
        $id = $_REQUEST["id"];
        Loader::model('Goodsattribute')->delAttribute($id);
    }
	
	/**
     * 获取商品属性
     */
    public function goodsAttributeDataList(){
        $page = $_REQUEST["page"];
        $limit = $_REQUEST["limit"];
        $arrData = Loader::model('Goodsattribute')->getAttributeData($page,$limit);
        echo json_encode($arrData);
    }





}